<?php
require_once ('../config/path_config.php');
require_once(ROOTDIR."admin/admin-header.php");
require_once(ROOTDIR."include/set_get_key.php");
require_once(ROOTDIR."common/db_utils.php");

$isAllow = isset($_SESSION['administrator']);
$isAllow |= isset($_SESSION['jgadmin']);
if ( !$isAllow ) {
	echo "<a href='../loginpage.php'>Please Login First!</a>";
	exit(1);
}

function genSql($pList) {
    $sql = "select * FROM privilege where rightstr in (";
    foreach ( $pList as $p ) {
        $sql .= "'".$p."',";
    }
    $sql = substr($sql, 0, strlen($sql) - 1);
    $sql .= ") order by user_id";
    return $sql;
}

$sql = "";
$pList = array('teacher', 'parent', 'viewcode_no_ac', 'viewcode_after_ac');
if ( isset($_SESSION['administrator']) ) {
    array_push($pList, 'administrator', 'jgadmin', 'xxadmin', 'problem_editor', 'problem_checker');
    $sql =genSql($pList);
}
else if ( isset($_SESSION['jgadmin']) ) {
    $pList = array('xxadmin');
    $sql =genSql($pList);
}

echo "<title>权限列表</title>";
echo "<br/><br/>";
echo "<div class='container'>";
$result = DbUtil::getInstance()->query($sql) ;
echo "<center><table class='table table-striped' width=60% border=1>";
echo "<thead><tr><td>用户名<td>权限码<td>操作</tr></thead>";
foreach($result as $row){
	echo "<tr>";
	echo "<td>".$row['user_id'];
	echo "<td>".$row['rightstr'];
	echo "<td><a href=privilege_delete.php?uid={$row['user_id']}&rightstr={$row['rightstr']}&getkey=".$_SESSION['getkey'].">Delete</a>";
	echo "</tr>";
}
echo "</table></center></div>";

?>
